package icegps.com.bhmap;

import android.app.Application;
import android.database.sqlite.SQLiteDatabase;

import icegps.com.bhmap.gen.DaoMaster;
import icegps.com.bhmap.gen.DaoSession;
import timber.log.Timber;

/**
 * Created by 111 on 2017/12/4.
 */

public class App extends Application {
    private static App app;
    private DaoMaster.DevOpenHelper devOpenHelper;
    private SQLiteDatabase db;
    private DaoMaster daoMaster;
    private DaoSession daoSession;

    @Override
    public void onCreate() {
        super.onCreate();
        app = this;
        Timber.plant(new Timber.DebugTree());
        setDatabase();
    }

    public static App getInstance() {
        return app;
    }

    private void setDatabase() {
        devOpenHelper = new DaoMaster.DevOpenHelper(this, "mapdata-db", null);
        db = devOpenHelper.getWritableDatabase();
        daoMaster = new DaoMaster(db);
        daoSession = daoMaster.newSession();
    }
    public DaoSession getDaoSession() {
        return daoSession;
    }
}

